#Copyright (c) 2025, Alibaba Cloud and its affiliates;
#Licensed under the Apache License, Version 2.0 (the "License");
#you may not use this file except in compliance with the License.
#You may obtain a copy of the License at

#   http://www.apache.org/licenses/LICENSE-2.0

#Unless required by applicable law or agreed to in writing, software
#distributed under the License is distributed on an "AS IS" BASIS,
#WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#See the License for the specific language governing permissions and
#limitations under the License.



# -*- coding: UTF-8 -*-
from flask_sqlalchemy import SQLAlchemy

# pip3 install flask-sqlalchemy
# https://codeantenna.com/a/qhYBtb7EgR

FCE_DB = SQLAlchemy()



class RayClusters(FCE_DB.Model):
    __tablename__ = 'rayclusters'
    id = FCE_DB.Column(FCE_DB.Integer, primary_key=True)
    cluster_name = FCE_DB.Column(FCE_DB.String(64), unique=True, index=True)
    cluster_version = FCE_DB.Column(FCE_DB.String(32), index=True)
    cluster_id = FCE_DB.Column(FCE_DB.String(64), unique=True, index=True)
    cluster_type = FCE_DB.Column(FCE_DB.String(32))
    #operater_image = FCE_DB.Column(FCE_DB.String(256))
    head_node = FCE_DB.Column(FCE_DB.String(1024))
    worker_groups = FCE_DB.Column(FCE_DB.String(1024))
    kube_config = FCE_DB.Column(FCE_DB.String(128))
    kube_cluster_id = FCE_DB.Column(FCE_DB.String(64), index=True)
    namespace = FCE_DB.Column(FCE_DB.String(64))
    status = FCE_DB.Column(FCE_DB.String(16))
    create_time = FCE_DB.Column(FCE_DB.Text(32))

class RayClustersDeleted(FCE_DB.Model):
    __tablename__ = 'rayclustersdeleted'
    id = FCE_DB.Column(FCE_DB.Integer, primary_key=True)
    cluster_name = FCE_DB.Column(FCE_DB.String(64), index=True)
    cluster_version = FCE_DB.Column(FCE_DB.String(32), index=True)
    cluster_id = FCE_DB.Column(FCE_DB.String(64), unique=True, index=True)
    cluster_type = FCE_DB.Column(FCE_DB.String(32))
    #operater_image = FCE_DB.Column(FCE_DB.String(256))
    head_node = FCE_DB.Column(FCE_DB.String(1024))
    worker_groups = FCE_DB.Column(FCE_DB.String(1024))
    kube_config = FCE_DB.Column(FCE_DB.String(128))
    kube_cluster_id = FCE_DB.Column(FCE_DB.String(64), index=True)
    namespace = FCE_DB.Column(FCE_DB.String(64))
    status = FCE_DB.Column(FCE_DB.String(16))
    create_time = FCE_DB.Column(FCE_DB.Text(32))
    delete_time = FCE_DB.Column(FCE_DB.Text(32))

class OssOperate(FCE_DB.Model):
    __tablename__ = 'oss_operate'
    id = FCE_DB.Column(FCE_DB.Integer, primary_key=True)
    time = FCE_DB.Column(FCE_DB.String(255), unique=True, index=True)
    time_info = FCE_DB.Column(FCE_DB.String(255))

def insert_db(obj):
    FCE_DB.session.add(obj)
    FCE_DB.session.commit()

def delete_db(obj):
    FCE_DB.session.delete(obj)
    FCE_DB.session.commit()
